// 引入router和store
import router from '@/router'
import store from '@/store'

const whiteList = ['/login']
router.beforeEach((to, from, next) => {
  // 模块名的token
  const token = store.state.user.token
  //  如果有token
  if (token) {
    // 直接放行
    next()
  } else {
    //  to.path配置的路由路径
    if (whiteList.includes(to.path)) {
      next()
    } else {
      // 最后跳到登陆页面
      next('/login')
    }
  }
})
